import Vue from 'vue'
import * as Util from '../../components/Util'

let CommonService = {
  install (Vue, options) {
    // 给vue增添对话框显示方法
    Vue.CommonService = Vue.prototype.$CommonService = CommonService
  },

  gasCalculate (model, pregas) {
    return Vue.resetpost('rs/logic/gasfeecalculate', {data: {model: model, isGasValue: 0, value: pregas}}, {resolveMsg: null, rejectMsg: '获取金额失败'})
  },

  feeCalculate (model, preamount) {
    return Vue.resetpost('rs/logic/gasfeecalculate', {data: {model: model, isGasValue: 1, value: preamount}}, {resolveMsg: null, rejectMsg: '获取气量失败'})
  },

  buildSellinggas (model, row) {
    return {
      f_balance: row.f_real_balance,
      f_curbalance: (row.f_real_balance - 0) + (model.f_collection - 0),
      f_user_balance: row.f_balance,
      f_meter_type: row.f_meter_type,
      f_payment: model.f_payment,
      f_user_id: model.f_user_id,
      f_userinfo_id: row.f_userinfo_id,
      f_user_name: row.f_user_name,
      f_user_type: row.f_user_type,
      f_gasproperties: row.f_gasproperties,
      f_address: row.f_address,
      f_meter_brand: row.f_meter_brand,
      f_meter_style: row.f_meter_style,
      f_meternumber: row.f_meternumber,
      f_price_id: row.f_price_id,
      f_collection: model.f_collection,
      f_operator: Util.f.name,
      f_charge_state: '有效'
    }
  },
  writeCardParams (cardParams) {
    console.log('common写卡参数，，，', cardParams)
    let result = {
      csql: cardParams.data.sc,
      lastmoney: cardParams.data.scje,
      ccsql: cardParams.data.ssc,
      lastlastmoney: cardParams.data.sscje,
      ljgql: cardParams.data.f_pregas,
      ljyql: cardParams.data.f_pregasall,
      yhh: cardParams.data.f_meterid,
      sxrq: cardParams.data.f_perform_date,
      totalmoney: cardParams.data.f_collection
    }

    // 对阶梯进行处理
    if (cardParams.data.stairprice.includes(';') && cardParams.data.stairamount.includes(';')) {
      let gases = cardParams.data.stairamount.split(';')
      let prices = cardParams.data.stairprice.split(';')
      if (gases.length >= 2) {
        result.stairgas1 = gases[0] !== '' ? gases[0] : 0
        result.stairgas2 = gases[1] !== '' ? gases[1] : 0
        result.stairgas3 = '99999999'
      }
      if (prices.length >= 2) {
        result.stairprice1 = prices[0] !== '' ? prices[0] : 0
        result.stairprice2 = prices[1] !== '' ? prices[1] : 0
        result.stairprice3 = prices[2] !== '' ? prices[2] : 0
      }
    } else {
      // 从固定气价的表换金额表的时候，气量随便写，金额用之前的固定单价
      result.stairgas1 = '77777777'
      result.stairgas2 = '88888888'
      result.stairgas3 = '99999999'

      result.stairprice1 = cardParams.data.stairprice
      result.stairprice2 = cardParams.data.stairprice
      result.stairprice3 = cardParams.data.stairprice
    }

    return result
  }
}

export default CommonService
